package it.orma.iridehr.cmis.config;

import java.util.HashMap;
import java.util.Map;

import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.springframework.beans.factory.FactoryBean;

public class CmisParameter implements FactoryBean<Map<String,String>> {

	private String urlAlfresco;
	private String username;
	private String password;
	
	public String getUrlAlfresco() {
		return urlAlfresco;
	}

	public void setUrlAlfresco(String urlAlfresco) {
		this.urlAlfresco = urlAlfresco;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public Map<String,String> getObject() throws Exception {
		Map<String,String> parameters = new HashMap<String,String>();
		parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
		parameters.put(SessionParameter.ATOMPUB_URL, urlAlfresco);
		parameters.put(SessionParameter.USER, username);
		parameters.put(SessionParameter.PASSWORD, password);
		parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
		parameters.put(SessionParameter.AUTH_HTTP_BASIC, "true" );
		parameters.put(SessionParameter.COOKIES, "true" );
		return parameters;
	}

	@Override
	public Class<?> getObjectType() {
		return Map.class;
	}

	@Override
	public boolean isSingleton() {
		
		return true;
	}

}
